package com.video.chat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.video.chat.domain.entity.MessageEntity;
import com.video.chat.domain.pojo.MsgLook;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChatMessageMapper extends BaseMapper<MessageEntity> {

    @Select("SELECT * FROM messages WHERE (sender_id = #{userId} AND receiver_id = #{friendId}) " +
            "OR (sender_id = #{friendId} AND receiver_id = #{userId}) " +
            "ORDER BY created_time ASC")
    List<MessageEntity> getChatHistory(Long userId, Long friendId);

    @Select("UPDATE messages SET is_read = '2' WHERE (sender_id = #{friendId} AND receiver_id = #{userId})")
    void updateRead(MsgLook msgLook);
}
